package cn.qy.java.base.ch12;

/**
 * @author acc8226
 */
public class Main {

	public static void main(String[] args) {
		Context<Number> context = new Context<>();
		context.setContext(123);
		System.out.println(context);
		
		// 测试泛型静态方法
		System.out.println(Context.newInstance(222));
		
		// 
		context.set(333);
		System.out.println(context);
	}
	
	static class Context<T> {
		
		T context;
		
		public Context() {
			this.context = null;
		}

		public Context(T t) {
			this.context = t;
		}

		public T getContext() {
			return context;
		}

		public void setContext(T context) {
			this.context = context;
		}
		
	    @Override
	    public String toString() {
	        return "context: " + this.context;
	    }
	    
	    public void set(T t) {
	    	this.context = t;
	    }
	    
	    public static <B> Context<B> newInstance(B b) {
	    	return new Context<>(b);
	    }
	}

}
